export const request = ({ url, data, header, method = 'GET' }) => {
  wx.showNavigationBarLoading();
  console.log(url);

  return new Promise((resolve, reject) => {
    wx.request({
      url,
      header: { 'Content-Type': 'application/json;charset=utf-8', ...header },
      data,
      method,
      success: function (result) {
        wx.hideNavigationBarLoading();
        
        if (result.data.code === '1') {
          const { msg } = result.data;
          wx.showToast({
            title: msg,
            icon: 'none',
            duration: 2000
          })
          reject(msg);
        } else {
          resolve(result.data);
        }
      },
      fail: function ({ errMsg }) {
        wx.hideNavigationBarLoading();
        wx.showToast({
          title: errMsg,
          icon: 'none',
          duration: 2000
        })
        reject(errMsg);
      }
    })
  });
}

// module.exports = request